/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2016
 */

package com.jzwl.site.manager.comment.dao;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.support.DataAccessUtils;
import org.springframework.stereotype.Repository;

import com.jzwl.common.constant.Constants;
import com.jzwl.common.id.Sequence;
import com.jzwl.system.base.dao.BaseDAO;
import com.jzwl.common.id.Sequence;
import com.jzwl.common.page.PageObject;
import com.jzwl.site.manager.comment.pojo.*;
import com.jzwl.site.manager.comment.dao.*;
import com.jzwl.site.manager.comment.service.*;



@Repository("siteArticleCommentDao")
public class SiteArticleCommentDao {
	
	@Autowired
	private BaseDAO baseDAO;//dao基类，操作数据库
	
	@Autowired
	private Constants constants;
	
	public String getColumns() {
		return ""
				+" t.cid as cid,"
				+" t.articleId as articleId,"
				+" t.content as content,"
				+" t.isPass as isPass,"
				+" t.createTime as createTime"
				;
	}
	

	public PageObject querySiteArticleCommentList(Map<String,Object> map) {
		
		String sql="select " + getColumns() + " from " + constants.getCurrentDB() + "site_article_comment t where 1=1 ";
		
		  	if(null !=map.get("articleId") && StringUtils.isNotEmpty(map.get("articleId").toString())){
			  		sql=sql+ " and t.articleId  = " + map.get("articleId") +"";
		  	}
		  	if(null !=map.get("content") && StringUtils.isNotEmpty(map.get("content").toString())){
			  		sql=sql+ " and t.content  = " + map.get("content") +"";
		  	}
		  	if(null !=map.get("isPass") && StringUtils.isNotEmpty(map.get("isPass").toString())){
			  		sql=sql+ " and t.isPass  = " + map.get("isPass") +"";
		  	}
		  	if(null !=map.get("createTime") && StringUtils.isNotEmpty(map.get("createTime").toString())){
			  		sql=sql+ " and t.createTime >= " + map.get("createTimeBegin") +"";
			  		sql=sql+ " and t.createTime <= " + map.get("createTimeEnd"  ) +"";
		  	}
		  	
		  	if(null !=map.get("beginDate") && StringUtils.isNotEmpty(map.get("beginDate").toString())){
		  		sql=sql+ " and t.createTime >= '" + map.get("beginDate") + " 00:00:00'";
		  	}
			
		  	if(null !=map.get("endDate") && StringUtils.isNotEmpty(map.get("endDate").toString())){
		  		sql=sql+ " and t.createTime <= '" + map.get("endDate")  + " 23:59:59'";
		  	}
		  	
		  	if(null !=map.get("isDelete") && StringUtils.isNotEmpty(map.get("isDelete").toString())){
			  		sql=sql+ " and t.isDelete  = " + map.get("isDelete") +"";
		  	}
					
					
		sql=sql+ " order by cid ";
		
		PageObject po = baseDAO.queryForMPageList(sql, new Object[]{},map);
		
		return po;
	}

	public boolean pass(Map<String, Object> map) {
		
		String sql ="update " + constants.getCurrentDB() + "site_article_comment set ";
				  	if(null !=map.get("articleId") && StringUtils.isNotEmpty(map.get("articleId").toString())){
					  	sql=sql+ "			articleId=:articleId ,";
				  	}
				  	if(null !=map.get("content") && StringUtils.isNotEmpty(map.get("content").toString())){
					  	sql=sql+ "			content=:content ,";
				  	}
				  	if(null !=map.get("isPass") && StringUtils.isNotEmpty(map.get("isPass").toString())){
					  	sql=sql+ "			isPass=:isPass ,";
				  	}
				  	if(null !=map.get("createTime") && StringUtils.isNotEmpty(map.get("createTime").toString())){
					  	sql=sql+ "			createTime=:createTime ,";
				  	}
				  	if(null !=map.get("isDelete") && StringUtils.isNotEmpty(map.get("isDelete").toString())){
					  	sql=sql+ "			isDelete=:isDelete ,";
				  	}
				sql = sql.substring(0, sql.length()-1);
				sql = sql + " where cid=:cid";
		return  baseDAO.executeNamedCommand(sql, map);
	}

	public boolean deleteSiteArticleComment(Map<String, Object> map) {
		
		String sql = "delete from " + constants.getCurrentDB() + "site_article_comment where cid in ("+ map.get("cid")+ " ) ";

		return baseDAO.executeNamedCommand(sql, map);
	}

	public boolean delSiteArticleComment(Map<String, Object> map) {
		
		String sql ="update " + constants.getCurrentDB() + "site_article_comment set "
				+ " isDelete =1 "
				+ " where cid=:cid";
		
		return  baseDAO.executeNamedCommand(sql, map);
	}
	

}
